/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: xhas_serialize_deserialize.h
 *
 * Purpose: check a structure is has serialize or deserialize member function
 *
 * Developer:
 *   wen.gu , 2023-08-08
 *
 * TODO:
 *
 ***************************************************************************/

#ifndef __XBUS_CORE_XHAS_MEMBER_FUNCTION_H__
#define __XBUS_CORE_XHAS_MEMBER_FUNCTION_H__

#include <cstdint>
#include <type_traits>


namespace xbus::protocol::runtime {

/** for check target has member function: void serialize(XSerializer& ser); */
template<typename T, typename... Args>
struct xhas_member_serialize {
private:
    template<typename U> static auto Check(int) -> decltype(std::declval<U>().serialize(std::declval<Args>()...), std::true_type());
    template<typename U> static std::false_type Check(...);
public:
    static constexpr auto value = decltype(Check<T>(0))::value;
    //enum { value = std::is_same<decltype(Check<T>(0)), std::true_type>::value };
};

/** for check target has member function: void deserialize(XDeserializer& dsr); */
template<typename T, typename... Args>
struct xhas_member_deserialize {
private:
    template<typename U> static auto Check(int) -> decltype(std::declval<U>().deserialize(std::declval<Args>()...), std::true_type());
    template<typename U> static std::false_type Check(...);
public:
    static constexpr auto value = decltype(Check<T>(0))::value;
    //enum { value = std::is_same<decltype(Check<T>(0)), std::true_type>::value };
};


} //namespace xbus::protocol::runtime


#endif /** !__XBUS_CORE_XHAS_MEMBER_FUNCTION_H__ */